package com.mask.mk.config.swagger;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @author: Joey
 * @Description:
 * @date:2023/4/25 13:44
 */

@Configuration
@EnableSwagger2   //开启swagger
public class SwaggerConfig {
    //配置bean实例 docket
    @Bean
    public Docket docket(Environment environment){
        //选择环境
        Profiles profiles = Profiles.of("dev");
        boolean flag =environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("PC") //分组名
                .enable(flag) // 配置启动开关
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.mask.mk.controller")) //指定扫描的接口文件  其他看typora
//                .paths(PathSelectors.ant("/com/**"))//过滤扫描 不让swagger扫描到
                .build();
    }
//    @Bean
//    public Docket docket2(Environment environment){
//        Profiles profiles = Profiles.of("dev");
//        boolean flag =environment.acceptsProfiles(profiles);
//
//        return new Docket(DocumentationType.SWAGGER_2)
//                .apiInfo(apiInfo())
//                .groupName("App")
//                .enable(flag) // 配置启动开关
//                .select()
//                .apis(RequestHandlerSelectors.basePackage("com.mask.mk.controller")) //指定扫描的接口文件  其他看typora
////                .paths(PathSelectors.ant("/com/**"))//过滤扫描 不让swagger扫描到
//                .build();
//    }
    //配置swagger 信息
    private ApiInfo apiInfo(){
        //作者
        Contact contact = new Contact("MASK后台API","[url]","x-jan@outlook.com");
        return new ApiInfo("Pc端-api文档",
                "@Author: fuHao &   \n" +
                        "使用GET & POST,接口请求参数大部分采用@RequestBody,所有接口访问权限暂时放开,无需登录认证",
                "2.3",
                "[url]",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
